<h1>Connexion</h1>
<?php
if (isset($_POST['connexion'])) 
{
	$req = $bdd->prepare('SELECT * FROM config WHERE identifiant = :identifiant AND motdepasse = :motdepasse');
	$req->execute(array(
		'identifiant' => $_POST['identifiant'],
		'motdepasse' => $_POST['motdepasse']));
	$resultat = $req->fetch();
	if (!$resultat)
	{
		echo 'Mauvais identifiant ou mot de passe !';
	}
	else
	{
		?>
		<p>Administrateur connecté.</p>
		<form method="post" action="./index.php?page=hivana">
			<input type="submit" name="deconnexion" value="Se déconnecter" class="bouton">
		</form>
		
		<?php
		$_SESSION['identifiant'] = $_POST['identifiant'];
		include ('./admin/admin_menu.php');
	}
}
elseif (isset($_POST['deconnexion'])) 
{
	unset($_SESSION);
	session_destroy();
	header ('Location: ./index.php?page=hivana');
}
else
{
	if ((isset($_SESSION['identifiant'])))
	{
		?>
		<p>Administrateur connecté.</p>
		<form id="deconnexion" name="deconnexion" method="post" action="./index.php?page=hivana">
			<input type="submit" name="deconnexion" value="Se déconnecter" class="bouton">
		</form>
		<?php
		include ('./admin/admin_menu.php');
	}
	else
	{
		?>
		<form method="post" action="./index.php?page=hivana">
			<table>
			<tr><td><label for="identifiant">Identifiant</label></td><td><input type="text" name="identifiant" id="identifiant" size="20" maxlength="10" required /></td></tr>
			<tr><td><label for="motdepasse">Mot de passe</label></td><td><input type="password" name="motdepasse" id="motdepasse" size="20" maxlength="10" required /></td></tr>
			<tr><td colspan="2"><input type="submit" name="connexion" value="Se connecter" /></td></tr>
			</table>
		</form>
		<?php
	}
}
?>
